<?php
use Entities\Obras;
$tipoBusca = $_REQUEST['tipoBusca'];
$strBusca = $_REQUEST['strBusca'];

$dql = "select c from Entities\Obras c where 1=1 ";
switch ($tipoBusca){
	case "nomeObra":
		$dql .= " and c.nomeObra like :parametro";
		$strBusca = "%$strBusca%";
		break;
	case "registroObra":
		$dql .= " and c.registroObra like :parametro";
		$strBusca = "%$strBusca%";
		break;
	case "engResponsavel":
		
		$dql = "select c from Entities\Obras c JOIN c.funcionario f where f.id = :parametro";
		$strBusca = "$strBusca";
		break;
	default:
		$dql .= " and 1>2";
}
$q = $em->createQuery($dql);
$q->setParameter("parametro", $strBusca);
$obras = $q->getResult();
$xml = "";
foreach ($obras as $obra){
	$xml .= "<obra>";
	$xml .= "<id>".$obra->getId()."</id>";
	$xml .= "<nomeObra>".$obra->getNomeObra()."</nomeObra>";
	$xml .= "<engResponsavel>".$obra->getFuncionario()->getNome()."</engResponsavel>";
	$xml .= "<registroObra>".$obra->getRegistroObra()."</registroObra>";
	$xml .= "</obra>";
}

echo $xml;